<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/rp/common/taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">
    
    <title>内部消息</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
	<script src="rp/scripts/boot.js" type="text/javascript"></script>
	
	<style type="text/css">
	   	
    </style>
	
  </head>
  
  <body class="body-fit">
  
  	<input type="hidden" id="readTrue" value="<rp:Button type="readTrue" buttons="${ buttons }"/>"/>
  	<input type="hidden" id="readFalse" value="<rp:Button type="readFalse" buttons="${ buttons }"/>"/>
  	<input type="hidden" id="writeMsg" value="<rp:Button type="writeMsg" buttons="${ buttons }"/>"/>
  	
  	<div id="tabs1" class="mini-tabs" activeIndex="0" tabPosition="left"
  		style="width:100%;height:100%;" bodyStyle="padding:0;border:0;">
	    <div title="<rp:Button type="tab_inbox" buttons="${ buttons }"/>">
			<div style="width:100%;">
		        <div class="mini-toolbar" style="padding:0px;border-top:0;border-left:0;border-right:0;">
		            <table style="width:100%;">
		                <tr>
		                    <td style="width:100%;">
		                        <a class="mini-button" onclick="setMarkRead()">
		                        	<i class="fa fa-check-circle-o fa-lg"></i> <rp:Button type="setMarkRead" buttons="${ buttons }"/></a>
		                        <a class="mini-button mini-button-danger" 
		                        	onclick="deleteInboxMessages()">
		                        	<i class="fa fa-trash-o fa-lg"></i> <rp:Button type="delete" buttons="${ buttons }"/></a>
						        <a class="mini-button" onclick="openWriteMsgWindow()"><i class="fa fa-edit fa-lg"></i> <rp:Button type="writeMsg" buttons="${ buttons }"/></a>    
		                    </td>
		                    <td style="white-space:nowrap;">
		                    	
		                    </td>
		                </tr>
		            </table>           
		        </div>
		    </div>
		    <div class="mini-fit">
	            <div id="inboxGrid" class="mini-datagrid" style="width:100%;height:100%;" 
	                borderStyle="border:0;" pageSize="20"
	                url="rp/system/msg/inboxData"
	                allowCellSelect="true" multiSelect="true" allowCellEdit="true"
	                showColumnsMenu="true" showColumnsMenu="true" onshowrowdetail="onShowRowDetail1">
	                <div property="columns">
	                	<div type="indexcolumn" headerAlign="center">序号</div>
	                	<div type="expandcolumn" width="40">查看详情</div>
		        		<div type="checkcolumn"></div>
		        		<div field="umId" headerAlign="center" visible="false" hideable="true">UMID</div>
	                    <div field="title" width="140" headerAlign="center">标题 </div>
	                    <div field="content" width="200" headerAlign="center" visible="false">内容</div>  
	                    <div field="markRead" width="40" headerAlign="center" align="center"
	                    	renderer="onMarkReadRenderer">状态</div>  
	                    <div field="creatorName" width="50" headerAlign="center" align="center">消息来自</div>
	                    <!-- <div width="50" headerAlign="center" renderer="onActionRenderer1">
	                    	操作
	                    </div> -->
	                    <div field="createDate" width="80" headerAlign="center" allowSort="true" renderer="onDateRenderer">
				        	创建日期
				        </div>  
	                </div>
	            </div>
	            
	        </div>
				
	    </div>
	    <div title="<rp:Button type="tab_outbox" buttons="${ buttons }"/>" iconCls="">
	        <div style="width:100%;">
		        <div class="mini-toolbar" style="padding:0px;border-top:0;border-left:0;border-right:0;">
		            <table style="width:100%;">
		                <tr>
		                    <td style="width:100%;">
		                        <a class="mini-button mini-button-danger" onclick="deleteOutboxMessages()"><i class="fa fa-trash-o fa-lg"></i> <rp:Button type="delete" buttons="${ buttons }"/></a>
						        <a class="mini-button" onclick="openWriteMsgWindow()"><i class="fa fa-edit fa-lg"></i> <rp:Button type="writeMsg" buttons="${ buttons }"/></a>    
		                    </td>
		                    <td style="white-space:nowrap;">
		                    	
		                    </td>
		                </tr>
		            </table>           
		        </div>
		    </div>
		    
		    <div class="mini-fit">
	            <div id="outboxGrid" class="mini-datagrid" style="width:100%;height:100%;" 
	                borderStyle="border:0;" pageSize="20"
	                url="rp/system/msg/outboxData"
	                allowCellSelect="true" multiSelect="true" allowCellEdit="true"
	                showColumnsMenu="true" onshowrowdetail="onShowRowDetail2">
	                <div property="columns">
	                	<div type="indexcolumn" headerAlign="center">序号</div>
	                	<div type="expandcolumn" width="40">查看详情</div>
		        		<div type="checkcolumn"></div>
	                    <div field="title" width="140" headerAlign="center">标题 </div>
	                    <div field="content" width="200" headerAlign="center" visible="false">内容</div>  
	                    <div field="receiver" width="120" headerAlign="center">接收人</div>
	                    <div field="readTrue" width="30" headerAlign="center" align="center">
	                    	<rp:Button type="readTrueHead" buttons="${ buttons }"/>
	                    </div>
	                    <div field="readFalse" width="30" headerAlign="center" align="center" renderer="onReadCountRenderer">
	                    	<rp:Button type="readFalseHead" buttons="${ buttons }"/>
	                    </div>
	                    <!-- <div width="80" headerAlign="center" renderer="">
	                    	操作
	                    </div> -->
	                    <div field="createDate" width="80" headerAlign="center" allowSort="true" renderer="onDateRenderer">
				        	创建日期
				        </div>  
	                </div>
	            </div>  
	            
	        </div>
	    </div>
	    
	</div>

	<div id="msgDetailContainer" style="display: none;">
		<div style="width:100%;">
	        <div id="msgDetail"></div>
	    </div>
	</div>
	
	<div id="msgDetailContainer2" class="mini-fit" style="display: none; height: auto;">
		<div style="width:100%;">
			<div style="width:100%;">
		        <div class="mini-toolbar" style="border-bottom:0;padding:3px;">
		            <span>接收人状态</span>           
		        </div>
		    </div>
			<div id="rsGrid" class="mini-datagrid" style="width:100%;height:150px;" 
            	url="rp/system/msg/getRecipientStatus" showEmptyText="true" showPager="false"
            	emptyText="没有接收人状态信息">
            	<div property="columns">
		        	<div field="realname" width="60" headerAlign="center">接收人姓名</div>    
			        <div field="markRead" width="120" headerAlign="center" renderer="onMarkReadRenderer">状态</div>
			        <div field="updateDate" width="80" headerAlign="center" allowSort="true" renderer="onDateRenderer">
			        	状态变更时间
			        </div>
		        </div>
			</div>
			<div id="msgDetail2"></div>
	    </div>
	</div>
  	
	<script type="text/javascript">
		var inboxGrid;
		var outboxGrid;
		var msgDetailContainer;//收件箱信息详情
		var msgDetailContainer2;//发件箱信息详情
		var rsGrid;
	
		$(function(){
			mini.parse();
			inboxGrid = mini.get("inboxGrid");
			inboxGrid.load();
			
			outboxGrid = mini.get("outboxGrid");
			outboxGrid.load();
			
			rsGrid = mini.get("rsGrid");
			
			msgDetailContainer = document.getElementById("msgDetailContainer");
			msgDetailContainer2 = document.getElementById("msgDetailContainer2");
		});
		
		function onShowRowDetail1(e) {
            var grid = e.sender;
            var row = e.record;
            
            var td = inboxGrid.getRowDetailCellEl(row);
            td.appendChild(msgDetailContainer);
            msgDetailContainer.style.display = "block";
			$("#msgDetail").html(row.content);
        }
		
		function onShowRowDetail2(e) {
            var grid = e.sender;
            var row = e.record;
            
            var td = outboxGrid.getRowDetailCellEl(row);
            td.appendChild(msgDetailContainer2);
            msgDetailContainer2.style.display = "block";
			$("#msgDetail2").html(row.content);
			
			rsGrid.load({messageId:row.id});
        }
		
		function onMarkReadRenderer(e){
			var record = e.record;
			if(record.markRead == "0"){
				return "<span style='color:red;'>"+$("#readFalse").val()+"</span>";
			}else if(record.markRead == "1"){
				return "<span style='color:green;'>"+$("#readTrue").val()+"</span>";
			}
		}
		
		function onReadCountRenderer(e){
			var value = e.value;
			if(value > 0){
				return "<span style='color:red;'>"+value+"</span>";
			}
			return "<span style='color:green;'>"+value+"</span>";
		}
		
		function setMarkRead(){
			var rows = inboxGrid.getSelecteds();
			if(rows.length == 0){
				mini.alert("请勾选需要操作的记录...");
			}else{
				var json = rp_encode(rows);
                if (rows.length > 0) {
                	rp_ajax("rp/system/msg/setMarkRead", {json: json}, function(result){
                		if(result == "success"){
                			//mini.alert("设置成功！");
                			inboxGrid.reload();
                		}
                    });
                }
			}
		}
		
		function openWriteMsgWindow(){
			mini.open({
                url: "rp/system/msg/msgForm.jsp",
                title: "<i class='fa fa-edit fa-lg'></i> "+$("#writeMsg").val(), 
                width: 750, 
                height: 550,
                //showMaxButton: true,
                onload: function () {
                	
                },
                ondestroy: function (action) {
                	inboxGrid.reload();
                	outboxGrid.reload();
                }
            });
		}
		
		function deleteInboxMessages() {
			var rows = inboxGrid.getSelecteds();
			if(rows.length == 0){
				mini.alert("请勾选需要删除的记录...");
			}else{
				mini.confirm("删除收件箱消息不会删除原消息，确定删除记录吗？", "友情提示",
		            function (action) {
		                if (action == "ok") {
		                    var json = rp_encode(rows);
		                    if (rows.length > 0) {
		                    	rp_ajax("rp/system/msg/deleteInboxMessages", {json: json}, function(result){
		                    		if(result == "success"){
			                    		mini.alert("删除成功");
			                    		inboxGrid.reload();
		                    		}
		                        });
		                    }
		                }
		            }
		        );
			}
        }
		
		function deleteOutboxMessages() {
			var rows = outboxGrid.getSelecteds();
			if(rows.length == 0){
				mini.alert("请勾选需要删除的记录...");
			}else{
				mini.confirm("确定删除记录吗？", "友情提示",
		            function (action) {
		                if (action == "ok") {
		                    var json = rp_encode(rows);
		                    if (rows.length > 0) {
		                    	rp_ajax("rp/system/msg/deleteOutboxMessages", {json: json}, function(result){
		                    		if(result == "success"){
			                    		mini.alert("删除成功");
			                    		inboxGrid.reload();
			                    		outboxGrid.reload();
		                    		}
		                        });
		                    }
		                }
		            }
		        );
			}
        }
		
	</script>
  </body>
</html>
